/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gui.manageplugins;

import java.awt.Component;
import java.util.Vector;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
import kernel.Plugin;

class MyLabelCell extends JLabel implements TableCellRenderer {

        Border unselectedBorder = null;
        Border selectedBorder = null;
        boolean isBordered = true;
        private JTable table;
        private JLabel renderLabel;
        private JLabel editLabel;
        private ManagePlugins list;

        public MyLabelCell(boolean isBordered) {
            this.isBordered = isBordered;
            setOpaque(true); //MUST do this for background to show up.
        }

        public MyLabelCell(JTable table, int column, ManagePlugins list) {
            super();
            this.table = table;
            renderLabel = new JLabel();

            editLabel = new JLabel();

            TableColumnModel columnModel = table.getColumnModel();
            columnModel.getColumn(column).setCellRenderer(this);
            //columnModel.getColumn(column).setCellEditor( this );
            this.list = list;
        }

        public Component getTableCellRendererComponent(JTable table,
                Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            renderLabel.setText((value == null ? "" : value.toString()));
            if (value != null) {
                String pluginName = value.toString().substring(0, value.toString().
                        lastIndexOf("-v")).trim();
                Vector<Plugin> vec = list.getListaPlugins();
                if(vec != null)
                for (int i = 0; i < vec.size(); i++) {
                    //System.out.println("comparando: "+vec.get(i).getName()+" con: "+pluginName);
                    if (vec.get(i).getName().equals(pluginName)) {
                        table.setToolTipText("<html><font color=black>" + vec.
                                get(i).getComentarios() + "</font></html>");
                        //System.out.println("commments: "+vec.get(i).getComentarios());
                        break;
                    }
                }
            //System.out.println("plugin_name: "+pluginName);
            }
            //System.out.println("value: "+table.getValueAt(row, column));
            return renderLabel;
        }
    }